﻿using System;
using System.IO;
using System.Linq;

namespace HttpCrawler
{
	public static class PathHelper
	{
		/// <summary>
		/// Creates all missing directories along the provided path
		/// </summary>
		/// <param name="filePath"></param>
		public static void CreateMissingDirectories(string filePath)
		{
			var filePathParts = Path.GetDirectoryName(filePath).Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries).Skip(1);

			string searchFilePath = Path.GetPathRoot(filePath);

			foreach (var filePathPart in filePathParts)
			{
				searchFilePath = Path.Combine(searchFilePath, filePathPart);

				if (!Directory.Exists(searchFilePath))
				{
					Directory.CreateDirectory(searchFilePath);
				}
			}
		}
	}
}
